#ifndef COMMON_MATHS_MIN_MAX_H
#define COMMON_MATHS_MIN_MAX_H


inline void MinMax(float a, float b, float c, float& mn, float&mx)
{
    if (a < b)
    {
        if (a < c)
        {
            mn = a;
            mx = (b > c) ? b : c;
        }
        else
        {
            mn = c;
            mx = b;
        }
    }
    else
    {
        if (b < c)
        {
            mn = b;
            mx = (a > c) ? a : c;
        }
        else
        {
            mn = c;
            mx = a;
        }
    }
}

inline float Min(float a, float b)
{
    return (a < b) ? a : b;
}

inline float Min(float a, float b, float c)
{
    float ab = (a < b) ? a : b;
    return (ab < c) ? ab : c;
}

inline float Min(float a, float b, float c, float d)
{
    float ab = (a < b) ? a : b;
    float cd = (c < d) ? c : d;
    return (ab < cd) ? ab : cd;
}

inline float Max(float a, float b)
{
    return (a > b) ? a : b;
}

inline float Max(float a, float b, float c)
{
    float ab = (a > b) ? a : b;
    return (ab > c) ? ab : c;
}

inline float Max(float a, float b, float c, float d)
{
    float ab = (a > b) ? a : b;
    float cd = (c > d) ? c : d;
    return (ab > cd) ? ab : cd;
}

inline float Clamp(float a, float mn, float mx)
{
    if (a < mn)
        a = mn;
    else if (a > mx)
        a = mx;
    return a;
}

inline float Saturate(float a)
{
    if (a < 0)
        a = 0;
    else if (a > 1)
        a = 1;
    return a;
}

inline size_t Min(size_t a, size_t b)
{
    return (a < b) ? a : b;
}

inline size_t Max(size_t a, size_t b)
{
    return (a > b) ? a : b;
}

inline int Min(int a, int b)
{
    return (a < b) ? a : b;
}

inline int Max(int a, int b)
{
    return (a > b) ? a : b;
}

#endif
